<template>
  <div class="list">
    <!-- <div class="pager-title">{{$route.meta.title}}</div> -->
    <el-form size="small" :inline="true" :model="whereData" class="search-from">
      <el-form-item>
        <el-input @keyup.enter.native="init()" clearable v-model="whereData.title" placeholder="用户账号"></el-input>
      </el-form-item>
      <!-- <el-form-item>
        <el-input @keyup.enter.native="fetchData()" clearable v-model="whereData.phone" placeholder="联系方式"></el-input>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="init()">查询</el-button>
        <el-button type="danger" @click="navigateTo('/tasks/create')">发布任务</el-button>
      </el-form-item>
    </el-form>
    <div class="section">
      <el-table
        :data="tableData"
        v-loading="isLoading"
        style="width: 100%">
        <el-table-column
          align="center"
          prop="id"
          label="ID">
        </el-table-column>
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="title"
          label="任务名称">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="settle_type"
          label="结算方式">
          <template slot-scope="scope">
            <span v-if="scope.row.settle_type === 1">面议</span>
            <span v-else-if="scope.row.settle_type === 2">计件</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="task_time"
          label="任务期限">
          <template slot-scope="scope">
            <span v-if="scope.row.settle_type === 1">长期</span>
            <span v-else-if="scope.row.settle_type === 2">时间段</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="check_type"
          label="审核模式">
          <template slot-scope="scope">
            <span v-if="scope.row.check_type === 1">自动审核</span>
            <span v-else-if="scope.row.check_type === 2">手动审核</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="is_default"
          label="默认任务">
          <template slot-scope="scope">
            <span v-if="scope.row.is_default === 1" style="color: #F56C6C">是</span>
            <span v-else>否</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="created_at"
          label="创建时间">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="opera"
          label="操作">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" @click="navigateTo(`/tasks/update?id=${scope.row.id}`)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
  name: 'list',
  data() {
    return {
      whereData: {
        title: '',
      },
      isLoading:false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      tableData: [],
    }
  },
  computed:{
    ...mapGetters([
      'userInfo'
    ])
  },
  mounted() {
    this.init()
  },
  methods: {
    navigateTo(url) {
      this.$router.push(url)
    },
    init() {
      this.$http.get('/company/task/list',{
        'title': this.whereData.title,
        'page': this.pageIndex,
        'limit': this.pageSize
      }).then(res => {
        if (res.code === 0) {
          this.tableData = res.page.list
          this.totalPage = res.page.totalCount
          this.amountData = res.amount
        }
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.init()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.init()
    }
  }
}
</script>
<style lang="less" scoped>
.uploader {
  display: inline-block;
  margin-left: 10px;
}
</style>
